package people.paper.tv.activity;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.PowerManager;

import com.skyworth.util.Util;
import com.umeng.analytics.MobclickAgent;

public abstract class BaseActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Util.instence(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
        disableScreenSaver();
    }

    @Override
    protected void onPause() {
        releaseScreenSaver();
        MobclickAgent.onPause(this);
        super.onPause();
    }

    private PowerManager.WakeLock mWakeLock = null;

    protected final void disableScreenSaver() {
        try {
            if (null == mWakeLock) {
                PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
                mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, getClass().getName());  // TAG为 Your class name
            }
            if (null != mWakeLock) {
                mWakeLock.acquire();
            }
        } catch (Exception e) {
        }
    }

    protected final void releaseScreenSaver() {
        try {
            if (mWakeLock != null) {
                mWakeLock.release();
                mWakeLock = null;
            }
        } catch (Exception e) {
        }
    }
}
